import { defineStore } from 'pinia'
import { ref } from 'vue'

//定义userStore

export const useMemberStore = defineStore('member',
        () => {
            const token = ref('')
            const code = ref('')
            const userInfo = ref({})
            //设置用户信息
            const setUserInfo = (val:any)=>{
                userInfo.value = val
            }
            const setToken=(val:any)=>{
                token.value = val
            }
            const setCode=(val:any)=>{
                code.value = val
            }
            //退出登录时，清除用户信息
            const cleanUserInfo = ()=>{
                userInfo.value = ''
                token.value = ''
                code.value = ''
            }
            return {
                userInfo,setUserInfo,cleanUserInfo,token,setToken,code,setCode
            }
            
        },
        //持久化存储信息
        //persist:true不适合小程序端
        {persist:{
            storage :{
                getItem(key){
                    return uni.getStorageSync(key)
                },
                setItem(key,value){
                    uni.setStorageSync(key,value)
                },
            }
        }
    }
)